import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// typedef  selectItem = void Function(int index);

class ItemTile extends StatefulWidget {
  final String url;
  final String title;
  final String subTitle;
  final bool isMark;
  final int timestamp;

  const ItemTile(this.url, this.title,
      {this.subTitle = '', this.timestamp, this.isMark = false});

  @override
  _ItemTileState createState() => _ItemTileState();
}

class _ItemTileState extends State<ItemTile> {
  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: ClipOval(
          child: widget.url == ""
              ? Image.asset(
                  'assets/icons/cat.jpeg',
                )
              : CachedNetworkImage(
                  imageUrl: widget.url,
                  placeholder: (context, url) => CircularProgressIndicator(),
                  errorWidget: (context, url, error) => ClipOval(
                        child: Image.asset(
                          'assets/icons/cat.jpeg',
                        ),
                      ))),
      title: Text(widget.title ?? ''),
      subtitle: Text(widget.subTitle ?? ''),
      // trailing: Container(alignment: Alignment.centerRight,child: Text('data'),),
      trailing: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Visibility(
              visible: widget.isMark,
              child: ClipOval(
                  child: Container(
                width: 30.w,
                height: 30.h,
                color: Colors.red,
              ))),
          widget.timestamp == null
              ? Text('')
              : Text(DateTime.fromMillisecondsSinceEpoch(widget.timestamp)
                  .toLocal()
                  .toString()
                  .substring(0, 16)),
        ],
      ),
    );
  }
}
